#include <sys/socket.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "utilities.h"
#include "listener.h"

int main(int argc, char *argv[]) {
	/** variables and such **/
	pid_t pid;

	/** fork for listening process **/
	pid = fork();
	if(pid < 0) {
		/** couldn't fork process, exit with error **/
		ErrorQuit("Unable to fork child process for listening\n");
	} else if(pid == 0) {
		/** inside child process, need to listen for connections **/
		if(argc > 0) {
			if(strcmp(argv[1], "false")) {
				ListenForPeers();
			}
		} else {
			ListenForPeers();
		}
	} else {
		/** parent process, need to load list cached of peers and start trying to connect **/
		printf("here is where we can continue looking for peers and connecting :)\n");
		while(1) { }
	}

	return EXIT_FAILURE;
}
